package com.runvp.rest.biz;

import com.runvp.common.annotation.Log;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.core.page.TableDataInfo;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.service.biz.domain.BizCustomerTranLog;
import com.runvp.service.biz.service.IBizCustomerTranLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户资金记录Controller
 * 
 * @author runvp
 * @date 2022-11-05
 */
@Controller
@RequestMapping("/biz/tranlog")
public class BizCustomerTranLogController extends BaseController {
    private String prefix = "biz/tranlog";

    @Autowired
    private IBizCustomerTranLogService bizCustomerTranLogService;

    @RequiresPermissions("biz:tranlog:view")
    @GetMapping()
    public String tranlog(ModelMap mmap,String tranType,String orderNo,Long customerId) {
//        mmap.put("tranTypeShow", tranType);
        mmap.put("orderNo", orderNo);
        mmap.put("customerIdShow", customerId);
        return prefix + "/tranlog";
    }

    /**
     * 查询用户资金记录列表
     */
    @RequiresPermissions("biz:tranlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizCustomerTranLog bizCustomerTranLog) {
        startPage();
        List<BizCustomerTranLog> list = bizCustomerTranLogService.selectBizCustomerTranLogList(bizCustomerTranLog);
        return getDataTable(list);
    }

    /**
     * 导出用户资金记录列表
     */
    @RequiresPermissions("biz:tranlog:export")
    @Log(title = "用户资金记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizCustomerTranLog bizCustomerTranLog) {
        List<BizCustomerTranLog> list = bizCustomerTranLogService.selectBizCustomerTranLogList(bizCustomerTranLog);
        ExcelUtil<BizCustomerTranLog> util = new ExcelUtil<BizCustomerTranLog>(BizCustomerTranLog.class);
        return util.exportExcel(list, "用户资金记录数据");
    }

    /**
     * 新增用户资金记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户资金记录
     */
    @ParamValid
    @RequiresPermissions("biz:tranlog:add")
    @Log(title = "用户资金记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizCustomerTranLog bizCustomerTranLog) {
        return toAjax(bizCustomerTranLogService.insertBizCustomerTranLog(bizCustomerTranLog));
    }

    /**
     * 修改用户资金记录
     */
    @RequiresPermissions("biz:tranlog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizCustomerTranLog bizCustomerTranLog = bizCustomerTranLogService.selectBizCustomerTranLogById(id);
        mmap.put("bizCustomerTranLog", bizCustomerTranLog);
        return prefix + "/edit";
    }
    /**
     * 用户资金记录详情
     */
    @RequiresPermissions("biz:tranlog:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizCustomerTranLog bizCustomerTranLog = bizCustomerTranLogService.selectBizCustomerTranLogById(id);
        mmap.put("bizCustomerTranLog", bizCustomerTranLog);
        return prefix + "/detail";
    }
    /**
     * 修改保存用户资金记录
     */
    @ParamValid
    @RequiresPermissions("biz:tranlog:edit")
    @Log(title = "用户资金记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizCustomerTranLog bizCustomerTranLog) {
        return toAjax(bizCustomerTranLogService.updateBizCustomerTranLog(bizCustomerTranLog));
    }

    /**
     * 删除用户资金记录
     */
    @RequiresPermissions("biz:tranlog:remove")
    @Log(title = "用户资金记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizCustomerTranLogService.deleteBizCustomerTranLogByIds(ids));
    }
}
